package com.example.myapplication.utils;

import android.app.ActivityManager;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;
import androidx.core.app.ActivityManagerCompat;

import java.util.ArrayList;
import java.util.List;

public class MySqliteHelper extends SQLiteOpenHelper{




    private static Context context;
    private static int versionDB = 1;
    private final static String dbName = "UserDB";//数据库名

    // 创建了 用户类
    String sql1 = "create table user (name varchar primary key," +
            "password varchar(20),age integer,information varchar)";

    // 创建了 文章类
    String sql2 = "create table article( id integer primary key autoincrement," +
            "date varchar,name varchar,information varchar)";

    List<String> sqls=new ArrayList<>();
    public MySqliteHelper(@Nullable Context context) {
        super(context, dbName, null, versionDB);
        sqls.add(this.sql1);
        sqls.add(this.sql2);
    }

    /**
     * 创建 Sql
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        for(String item :sqls){
            db.execSQL(item);
        }
    }

    /**
     *
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }


}
